/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.feedback;

import com.apt.bean.FeedBacks;
import com.apt.tag.Process_Page;
import java.util.HashMap;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author Bach
 */
public class FreedbackTag extends SimpleTagSupport {

    private String page;
    private String adminid;

    /**
     * Called by the container to invoke this tag. The implementation of this
     * method is provided by the tag library developer, and handles all tag
     * processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        int cursor1;
        HashMap<Integer, FeedBacks> hm = GetListFeedBack.getListFeeedBack();
        try {
            if (hm != null && hm.size() != 0) {
                out.println(Process_Page.divPage(page, hm.size(), 9));
                int uid_f = 1;
                int uid_l = 30;

                try {
                    cursor1 = Integer.parseInt(page);

                } catch (NumberFormatException ex) {
                    cursor1 = 1;
                }
                if (cursor1 > 1) {
                    uid_f = (cursor1 - 1) * 30;
                    uid_l = cursor1 * 30;
                }
                int current_page = uid_l / 30;
                for (int i = uid_f; i < uid_l; i++) {
                    FeedBacks u = hm.get(i);
                    if (u != null) {

                        StringBuilder sb = new StringBuilder(" <tr>");
                        // sb.append(" <td><input type='checkbox' /></td>");
                        sb.append("<td>" + u.getUser_Name() + "</td>");
                        sb.append("  <td><a href=\"#\" title=\"title\">" + u.getCreated_Time() + "t</a></td>");
                        sb.append("    <td>");
                        sb.append("        <!-- Icons -->");
                        sb.append("<a href=\"DisableFeeback?user_id=" + u.getAccount_Id() + "&pageno=" + current_page + "\" title=\"Disable\"><img src=\"resources/images/icons/cross.png\" alt=\"Disable\" /></a>");
                        sb.append(" <a href=\"Navigation?menu=10&user_id=" + u.getAccount_Id()+"&idAD="+adminid + "&content=" + u.getFeedback_Text() + "&pageno=" + current_page + "\" title=\"View\" ><img src=\"resources/images/icons/view.png\" alt=\"View\" /></a>");
                        sb.append("   </td>");
                        sb.append(" </tr>");

                        out.print(sb.toString());

                    }
                }
            }
            JspFragment f = getJspBody();
            if (f != null) {
                f.invoke(out);
            }

        } catch (java.io.IOException ex) {
            throw new JspException("Error in FreedbackTag tag", ex);
        }



    }

    public void setPage(String page) {
        this.page = page;
    }

    /**
     * @return the adminid
     */
    public String getAdminid() {
        return adminid;
    }

    /**
     * @param adminid the adminid to set
     */
    public void setAdminid(String adminid) {
        this.adminid = adminid;
    }
}
